package com.app;

import com.view.LoginView;
import com.view.RegisterView;

import java.util.Map;

import static com.util.Read.getIn;

public class App {
    public static void main() {
        System.out.println("欢迎使用记账本：");
        int n = 0;
        LoginView loginView = null;
        RegisterView registerView = null;
        while (n != 1 && n != 2) {
            System.out.println("请选择功能：\n1.登录\t2.注册");
            n = getIn().nextInt();
            switch (n) {
                case 1:
                    loginView = new LoginView();

                    break;
                case 2:
                    registerView = new RegisterView();
                    registerView.register();
                    break;
                default:
                    System.out.println("请选择1或2！");
                    main();
                    break;
            }
        }

        if (registerView == null && loginView == null) {
            System.exit(0);
        }
        Map<String, Object> map = loginView.login();
        if (map != null) {
            loginView.setInfo(map);
            loginView.menu();
            System.out.println(loginView.getInfo());
        } else {
            System.out.println("用户名或密码有误！请重新输入");
            main();
        }
        System.out.println("===================================================");
    }

    public static void main(String[] args) {
        main();
    }
}
